package Recursion;

import java.util.ArrayList;

public class Permutation {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Permutation a = new Permutation();
		a.permute("ABBC");
	}

	public void permute(String str) {
		char[] a = str.toCharArray();
		ArrayList<Character> c = new ArrayList<Character>(); 
		for (int i = 0; i < a.length; i++) {
			if (!c.contains(a[i])) {
				c.add(a[i]);
			}
		}
		permute(c.toArray(), 0);
	}
	
	private void permute(Object[] list, int low) {
		if (low == list.length) {
			for (Object c : list) {
				System.out.print(c);
			}
			System.out.println();
		} else {
			for (int i = low; i < list.length; i++) {
				swap(list, low, i);
				permute(list, low + 1);
				swap(list, low, i);
			}
		}
	}

	private void swap(Object[] list, int low, int i) {
		Object a;
		a = list[low];
		list[low] = list[i];
		list[i] = a;
	}

	
	

}
